﻿{% extends "base.html" %}
{% block scripts %}
{% endblock %}
{% block content %}
    <h1>Обсуждения</h1>

    {% if discussions.object_list %}
        <ul class="paging">
            {% if discussions.has_previous %}
                <li class="item"><a href="/discussions/{{ discussions.previous_page_number }}/"><img class="icon" src="/media/images/icon_arrow_2.gif" width="11" height="5"></a></li>
            {% endif %}
            {% for page in discussions.paginator.page_range %}
                {% if page == discussions.number %}
                    <li class="item item_current">{{ page }}</li>
                {% else %}
                    <li class="item"><a href="/discussions/{{ page }}/">{{ page }}</a></li>
                {% endif %}
            {% endfor %}
            {% if discussions.has_next %}
                <li class="item"><a href="/discussions/{{ discussions.next_page_number }}/"><img class="icon" src="/media/images/icon_arrow_1.gif" width="11" height="5"></a></li>
            {% endif %}
        </ul>
    {% endif %}

    <ul class="debate_list debate_list_all">

        {% for discussion in info.discussions %}
            <li class="item{% if forloop.first %} item_first{% endif %}">
                <h3 class="cat"><a href="/discussion/{{ discussion.id }}/">{{ discussion.subj }}</a> <span class="icon"></span></h3>
                <div class="mess_num">{{ discussion.messages.count }} сообщений</div>
                <div class="date">{{ discussion.creation_date }}</div>
                {% if discussion.get_last_post %}
                    <div class="user_info">
                        <div class="username">
                            <a href="/profile/{{ discussion.get_last_post.publisher.id }}/">
                                <img class="userpic"
                                        {% if discussion.get_last_post.publisher.user_info.avatar %}
                                     src="{{ discussion.get_last_post.publisher.user_info.avatar.url }}"
                                        {% if discussion.get_last_post.publisher.user_info.avatar.width > discussion.get_last_post.publisher.user_info.avatar.height %}
                                     width="36"
                                        {% else %}
                                     height="40"
                                        {% endif %}
                                        {% else %}
                                     src="/media/images/nophoto.jpg/" width="36" height="40"   {% endif %}
                                        />
                                {{ discussion.get_last_post.publisher.user_info.last_name }} {{ discussion.get_last_post.publisher.user_info.first_name }}
                            </a>
                        </div>
                        <div class="date">{{ discussion.get_last_post.post_date }}</div>
                    </div>
                {% endif %}
            </li>
        {% endfor %}
    </ul>
    
    {% if discussions.object_list %}
        <ul class="paging">
            {% if discussions.has_previous %}
                <li class="item"><a href="/discussions/{{ discussions.previous_page_number }}/"><img class="icon" src="/media/images/icon_arrow_2.gif" width="11" height="5"></a></li>
            {% endif %}
            {% for page in discussions.paginator.page_range %}
                {% if page == discussions.number %}
                    <li class="item item_current">{{ page }}</li>
                {% else %}
                    <li class="item"><a href="/discussions/{{ page }}/">{{ page }}</a></li>
                {% endif %}
            {% endfor %}
            {% if discussions.has_next %}
                <li class="item"><a href="/discussions/{{ discussions.next_page_number }}/"><img class="icon" src="/media/images/icon_arrow_1.gif" width="11" height="5"></a></li>
            {% endif %}
        </ul>
    {% endif %}

    <div class="add_debate">
        <h2 class="block_header">Начать новую тему</h2>
        <form action="/start_discussion/" id="id_start_discussion_form" method="post">
            <input class="text_input" id="id_subj" name="subj" placeholder="Введите название">
            <input class="button" id="id_start_discussion_button" type="submit" value="Добавить">
        </form>
    </div>
{% endblock %}